﻿using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;

namespace AbpVnext_Module.Interceptor
{
    [Dependency(ServiceLifetime.Transient)]
    public class LoggerInterceptor : AbpInterceptor
    {
        /// <summary>
        /// 动态代理使用
        /// 动态在执行的方法中，添加新的业务逻辑执行之前。记录日志，执行之后，记录日志
        /// AOP 拦截器
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            //throw new NotImplementedException();
            //方法执行之前
            Console.WriteLine("记录日志之前");
            //执行方法
            await invocation.ProceedAsync();
            //方法执行之后
            Console.WriteLine("记录日志记录日志之后");
            //return Task.CompletedTask;
        }
    }
}
